package com.ws.haungjia.controller;

import com.ws.haungjia.Bean.Shangjia;
import com.ws.haungjia.Service.ShangjiaService;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/shangjia")
public class Shangjiaconfig {
    @Autowired
    private ShangjiaService shangjiaService;

    @RequestMapping("/cha")
    public String cha(Model model){
        List<Shangjia> cha = shangjiaService.cha();
        model.addAttribute("merchantList",cha);
        return "WEB-INF/houtai/shangjia/list" ;
    }

    @RequestMapping("/zengjia")
    public String tianjia(String sname, String slianxi){
        System.out.println(sname+"---"+slianxi);
        int tianjia = shangjiaService.tianjia(sname, slianxi);
        System.out.println(tianjia);
        if (tianjia>0){
            System.out.println("添加成功");
            return "redirect:/shangjia/cha";
        }else{
            return "redirect:shangjia/tiaozhuan" ;
        }

    }

    @RequestMapping("/shan")
    public String shan(int id){
        shangjiaService.shan(id);
        return "redirect:/shangjia/cha";
    }

    @RequestMapping("/huixian")
    public String huixian(int id,Model model){
        Shangjia huixian = shangjiaService.huixian(id);
        model.addAttribute("shang",huixian);
        return "WEB-INF/houtai/shangjia/xiugai" ;
    }

    @RequestMapping("/xiugai")
    public String xiugai(int id,String sname,String slianxi){
        int xiugai = shangjiaService.xiugai( sname, slianxi,id);
        if (xiugai>0){
            System.out.println("修改成功");
            return "redirect:/shangjia/cha";
        }else{
            return "redirect:shangjia/tiaozhuan" ;
        }
    }

    @RequestMapping("/tiaozhuan")
    public String tiaozhuan(){
        return "WEB-INF/houtai/shangjia/zengjia" ;
    }
}
